# coding=utf-8


from io import StringIO
from typing import List

from utils.payload import EncodeType


class Property:

    def __init__(self,prop_name:str,isDirectTransmit=False) -> None:
        self.prop_name=prop_name
        self.prop_id:str=None
        self.isDirectTransmit=isDirectTransmit
        self.change_mode:str=None
        self.access_mode:str=None
        self.prop_type:str=None
        self.prop_area:str=None
        self.description:str=""
        self.publisher:str=None
        self.subscriber:str=None
        self.encodeType:str=None
        self.prop_module:str=None
        self.prop_date:str=None
        self.prop_swraid:str=None
        self.prop_author:str=None
        self.prop_internal:bool=False
        self.propEnums:str=None

    def setPropId(self,id):
        self.prop_id=id

    def setChangeMode(self,mode):
        self.change_mode=mode

    def setAccessMode(self,mode):
        self.access_mode=mode

    def setPropType(self,propType):
        self.prop_type=propType

    def setPropArea(self,area):
        self.prop_area=area

    def setDesc(self,desc):
        if desc is not None:
            with StringIO(desc) as ios:
                self.description="\t".expandtabs(1).join([line.strip() for line in ios.readlines()])

    def setPublisher(self,publisher):
        self.publisher=publisher

    def setSubscriber(self,subscriber):
        self.subscriber=subscriber


    def setEncodeType(self,encodeType:str):
        self.encodeType=encodeType

    def setPropDate(self,date):
        self.prop_date=date

    def setPropAuthor(self,author):
        self.prop_author=author

    def setPropInternal(self,isInternalProp):
        self.prop_internal=isInternalProp

    def setPropModule(self,module):
        self.prop_module=module

    def setPropSwraid(self,swraid):
        self.prop_swraid=swraid

    def setPropEnums(self,propEnums):
        self.propEnums=propEnums


class TypesHal:

    def __init__(self) -> None:
        self.props:List[Property]=[]
        self.adasProps:List[Property]=[]
        self.chargingProps:list[Property]=[]
        self.hvacProps:List[Property]=[]
        self.drivemodeProps:List[Property]=[]
        self.audioProps:List[Property]=[]
        self.dvrProps:List[Property]=[]
        self.hudProps:List[Property]=[]
        self.seatProps:List[Property]=[]
        self.doorProps:List[Property]=[]
        self.windowProps:List[Property]=[]
        self.lightProps:List[Property]=[]
        self.wpcProps:List[Property]=[]
        self.mirrorProps:List[Property]=[]
        self.wheelProps:List[Property]=[]
        self.energyProps:List[Property]=[]
        self.tripProps:List[Property]=[]
        self.vehicleProps:List[Property]=[]
        self.dimProps:List[Property]=[]
        self.enums:List[EncodeType]=[]
        self.propList = []

    def addProperty(self,prop):
        self.props.append(prop)

    def addAdasProperty(self,prop):
        self.adasProps.append(prop)

    def addChargingProperty(self,prop):
        self.chargingProps.append(prop)

    def addHvacProperty(self,prop):
        self.hvacProps.append(prop)

    def addDrivemodeProperty(self,prop):
        self.drivemodeProps.append(prop)

    def addAudioProperty(self,prop):
        self.audioProps.append(prop)

    def addDvrProperty(self,prop):
        self.dvrProps.append(prop)

    def addHudProperty(self,prop):
        self.hudProps.append(prop)

    def addSeatProperty(self,prop):
        self.seatProps.append(prop)

    def addDoorProperty(self,prop):
        self.doorProps.append(prop)

    def addWindowProperty(self,prop):
        self.windowProps.append(prop)

    def addLightProperty(self,prop):
        self.lightProps.append(prop)

    def addWpcProperty(self,prop):
        self.wpcProps.append(prop)

    def addMirrorProperty(self,prop):
        self.mirrorProps.append(prop)

    def addWheelProperty(self,prop):
        self.wheelProps.append(prop)

    def addEnergyProperty(self,prop):
        self.energyProps.append(prop)

    def addTripProperty(self,prop):
        self.tripProps.append(prop)

    def addVehicleProperty(self,prop):
        self.vehicleProps.append(prop)

    def addDimProperty(self,prop):
        self.dimProps.append(prop)

    def addEnum(self,enum):
        self.enums.append(enum)

    def extend(self,other):
        self.props.extend(other.props)
        self.enums.extend(other.enums)


